﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MovieRental.EnhancedEntities;
using MovieRental_Presentation.Helpers;

namespace MovieRental_Presentation.DataViews
{
    public class ReturnLoanDataView : BaseDataView
    {
        private IEnumerable<Loan> _loans;

        public ReturnLoanDataView(IEnumerable<Loan> loans)
        {
            Loans = loans;
        } 

        public IEnumerable<Loan> Loans
        {
            set { SetProperty <IEnumerable<Loan>>(ref _loans, value, "Loans"); }
            get { return _loans; }
        }

        public double Discount
        {
            get { return ComponentManager.Instance.LoanCartComponent.Get(Loans.First().Entity.LoanCartId).CartDiscountValue; }
        }

        public double TotalPrice
        {
            get { return ComponentManager.Instance.LoanCartComponent.CalculateMustPayFee(Loans.Select(x => x.Entity)); }
        }

        public string CustomerName
        {
            get
            {
                var customerComponent = ComponentManager.Instance.CustomerComponent;
                var customer = customerComponent.Get(ComponentManager.Instance.LoanCartComponent.Get(Loans.First().Entity.LoanCartId).CustomerId);
                return string.Format("{0} {1}", customer.FirstName, customer.LastName);
            }
        }
    }
}
